<div class="m-bg">
<h1>SQL DELETE 语句</h1>
<p class="intro">DELETE 语句用于删除表中的记录。</p> <h2>SQL DELETE 语句</h2> <p>DELETE 语句用于删除表中的行。</p> <h3>SQL DELETE 语法</h3> <div class="code notranslate"><pre><code class="language-sql"><div> DELETE FROM <em>table_name</em><br/> WHERE <em>some_column</em>=<em>some_value</em>;</div></code></pre></div> <br/><table class="lamp"><tr>
<th width="34"><span aria-hidden="true" class="g-bg glyphicon glyphicon-flag margin-l-5"></span></th> <td> <strong>请注意 SQL DELETE 语句中的 WHERE 子句！</strong><br/> WHERE 子句规定哪条记录或者哪些记录需要删除。如果您省略了 WHERE 子句，所有的记录都将被删除！</td> </tr></table>
<h2>演示数据库</h2> <p>在本教程中，我们将使用众所周知的 Northwind 样本数据库。</p> <p>下面是选自 "Customers" 表的数据：</p> <table class="reference notranslate">
<tr>
<th>CustomerID</th> <th>CustomerName</th> <th>ContactName</th> <th>Address</th> <th>City</th> <th>PostalCode</th> <th>Country</th> </tr>
<tr>
<td>1<br/><br/>
</td> <td>Alfreds Futterkiste</td> <td>Maria Anders</td> <td>Obere Str. 57</td> <td>Berlin</td> <td>12209</td> <td>Germany</td> </tr>
<tr>
<td>2</td> <td>Ana Trujillo Emparedados y helados</td> <td>Ana Trujillo</td> <td>Avda. de la Constitución 2222</td> <td>México D.F.</td> <td>05021</td> <td>Mexico</td> </tr>
<tr>
<td>3</td> <td>Antonio Moreno Taquería</td> <td>Antonio Moreno</td> <td>Mataderos 2312</td> <td>México D.F.</td> <td>05023</td> <td>Mexico</td> </tr>
<tr>
<td>4<br/><br/>
</td> <td>Around the Horn</td> <td>Thomas Hardy</td> <td>120 Hanover Sq.</td> <td>London</td> <td>WA1 1DP</td> <td>UK</td> </tr>
<tr>
<td>5</td> <td>Berglunds snabbköp</td> <td>Christina Berglund</td> <td>Berguvsvägen 8</td> <td>Luleå</td> <td>S-958 22</td> <td>Sweden</td> </tr>
</table>
<h2>SQL DELETE 实例</h2> <p>假设我们要从 "Customers" 表中删除客户 "Alfreds Futterkiste"。</p> <p>我们使用下面的 SQL 语句：</p> <div class="example margin-b-10"> <h2 class="example">实例</h2> <pre><code class="language-sql"><div class="example_code notranslate"> DELETE FROM Customers<br/> WHERE CustomerName='Alfreds Futterkiste' AND ContactName='Maria Anders'; </div></code></pre> </div> <p>现在，"Customers" 表如下所示：</p> <table class="reference notranslate">
<tr>
<th>CustomerID</th> <th>CustomerName</th> <th>ContactName</th> <th>Address</th> <th>City</th> <th>PostalCode</th> <th>Country</th> </tr>
<tr>
<td>2</td> <td>Ana Trujillo Emparedados y helados</td> <td>Ana Trujillo</td> <td>Avda. de la Constitución 2222</td> <td>México D.F.</td> <td>05021</td> <td>Mexico</td> </tr>
<tr>
<td>3</td> <td>Antonio Moreno Taquería</td> <td>Antonio Moreno</td> <td>Mataderos 2312</td> <td>México D.F.</td> <td>05023</td> <td>Mexico</td> </tr>
<tr>
<td>4<br/><br/>
</td> <td>Around the Horn</td> <td>Thomas Hardy</td> <td>120 Hanover Sq.</td> <td>London</td> <td>WA1 1DP</td> <td>UK</td> </tr>
<tr>
<td>5</td> <td>Berglunds snabbköp</td> <td>Christina Berglund</td> <td>Berguvsvägen 8</td> <td>Luleå</td> <td>S-958 22</td> <td>Sweden</td> </tr>
</table>
<h2>删除所有数据</h2> <p>您可以在不删除表的情况下，删除表中所有的行。这意味着表结构、属性、索引将保持不变：</p> <div class="code notranslate"><pre><code class="language-sql"><div> DELETE FROM <em>table_name</em>;<br/><br/> or<br/><br/> DELETE * FROM <em>table_name</em>;</div></code></pre></div> <p><b>注释：</b>在删除记录时要格外小心！因为您不能重来！</p> <div class="text-center padding-10 margin-t-5">
</div>
</div>